package com.springboot.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.springboot.service.FileUploadService;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


public class testServlet extends HttpServlet {
    @Autowired
    FileUploadService fileUploadService;

    protected void doPost(HttpServletRequest request, HttpServletResponse response, MultipartFile file) throws ServletException, IOException {
        String excelPath = "C:\\Users\\mier\\Desktop\\Excel\\test.xlsx";
        String path = "Excel";
        try {
            excelPath=fileUploadService.uploadExcel(file,path);
            excelPath="\"" + excelPath + "\"";
            System.out.println("........");
            System.out.println(excelPath);
        }
        catch (Exception e)
        {
            System.out.println("UploadExcelController 出错");
            e.printStackTrace();
        }
        HttpSession session = request.getSession();
        session.setAttribute("excelPath",excelPath);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
